package cn.wizzer.app.web.modules.controllers.platform.sys;

import cn.wizzer.app.user.modules.services.UserLogService;
import cn.wizzer.app.web.commons.utils.DateUtil;
import cn.wizzer.app.web.commons.utils.PageUtil;
import cn.wizzer.framework.util.Result;
import com.alibaba.dubbo.config.annotation.Reference;
import org.apache.commons.lang3.StringUtils;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.nutz.ioc.loader.annotation.Inject;
import org.nutz.ioc.loader.annotation.IocBean;
import org.nutz.log.Log;
import org.nutz.log.Logs;
import org.nutz.mvc.annotation.At;
import org.nutz.mvc.annotation.Ok;
import org.nutz.mvc.annotation.Param;

import javax.servlet.http.HttpServletRequest;

/**
 * Created by wizzer on 2016/6/29.
 */
@IocBean
@At("/platform/user/log")
public class UserLogController {
    private static final Log log = Logs.get();
    @Inject
    @Reference
    private UserLogService userLogService;

    @At("")
    @Ok("beetl:/platform/sys/log/user/index.html")
    @RequiresPermissions("user.manager.log")
    public void index(HttpServletRequest req) {
        req.setAttribute("today", DateUtil.getDate());
    }

    @At
    @Ok("json:full")
    @RequiresPermissions("user.manager.log")
    public Object data(@Param("searchDate") String searchDate,
                       @Param("searchKeyword") String searchKeyword,
                       @Param("operation") String operation,
                       @Param("pageNumber") int pageNumber,
                       @Param("pageSize") int pageSize,
                       @Param("pageOrderName") String pageOrderName,
                       @Param("pageOrderBy") String pageOrderBy) {
        String[] date = StringUtils.split(searchDate, ",");
        return Result.success().addData(userLogService.data(date, searchKeyword, operation, pageOrderName,
                PageUtil.getOrder(pageOrderBy), pageNumber, pageSize));
    }
}
